package org.jeecg.modules.prodorder.controller;

import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.FillRuleUtil;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.cusorder.entity.CusOrderInfo;
import org.jeecg.modules.cusorder.mapper.CusOrderInfoMapper;
import org.jeecg.modules.cusorder.service.ICusOrderInfoService;
import org.jeecg.modules.cusstyle.service.ICusStyleInfoService;
import org.jeecg.modules.prodorder.entity.ProductionOrderInfo;
import org.jeecg.modules.prodorder.mapper.ProductionOrderInfoMapper;
import org.jeecg.modules.prodorder.service.IProductionOrderInfoService;
import org.jeecg.modules.prodorder.vo.OpenBomVO;
import org.jeecg.modules.prodorder.vo.OpenProdOrderFormVO;
import org.jeecg.modules.prodorder.vo.OpenProdOrderVO;
import org.jeecg.modules.system.controller.SysAnnouncementController;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysUserMapper;
import org.jeecg.modules.system.service.ISysDepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

 /**
 * @Description: 生产工单
 * @Date:   2021-09-09
 * @Version: V1.0
 */
@Api(tags="生产工单")
@RestController
@RequestMapping("/productionOrderInfo")
@Slf4j
public class ProductionOrderInfoController extends JeecgController<ProductionOrderInfo, IProductionOrderInfoService>{
	
	@Autowired
	private SysUserMapper userMapper;
	
	@Autowired
	private ISysDepartService sysDepartService;
	
	@Autowired
	private IProductionOrderInfoService productionOrderInfoService;
	
	@Autowired
	private ICusStyleInfoService cusStyleInfoService;
	
	@Autowired
	private ICusOrderInfoService cusOrderInfoService;
	
	@Autowired
	private CusOrderInfoMapper cusOrderInfoMapper;
	
	@Autowired
	private ProductionOrderInfoMapper productionOrderInfoMapper;
	
	
	
	/**
	 * 生产跟单-分页列表查询
	 *
	 * @param productionOrderInfo
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "生产跟单-分页列表查询")
	@ApiOperation(value="生产跟单-分页列表查询", notes="生产跟单-分页列表查询")
	@GetMapping(value = "/rootList")
	@PermissionData(pageComponent="prodOrder/ProductionOrderInfoList")
	public Result<?> queryPageList(ProductionOrderInfo productionOrderInfo,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		String hasQuery = req.getParameter("hasQuery");
        if(hasQuery != null && "true".equals(hasQuery)){
            QueryWrapper<ProductionOrderInfo> queryWrapper =  QueryGenerator.initQueryWrapper(productionOrderInfo, req.getParameterMap());
            queryWrapper.orderByAsc("sn");
            queryWrapper.eq("is_merged", 0);//被合并的工单不再显示
            queryWrapper.eq("is_splited", 0);//被拆过的工单不再显示
            queryWrapper.eq("store_by", loginUser.getUsername());//当前登录用户
            List<ProductionOrderInfo> list = productionOrderInfoService.queryTreeListNoPage(queryWrapper);
            IPage<ProductionOrderInfo> pageList = new Page<>(1, 10, list.size());
            pageList.setRecords(list);
            return Result.OK(pageList);
        }else{
            String parentId = productionOrderInfo.getPid();
            if (oConvertUtils.isEmpty(parentId)) {
                parentId = "0";
            }
            productionOrderInfo.setPid(null);
            QueryWrapper<ProductionOrderInfo> queryWrapper = QueryGenerator.initQueryWrapper(productionOrderInfo, req.getParameterMap());
            // 使用 eq 防止模糊查询
            queryWrapper.eq("pid", parentId);
            queryWrapper.eq("is_merged", 0);//被合并的工单不再显示
            queryWrapper.eq("is_splited", 0);//被拆过的工单不再显示
            queryWrapper.eq("store_by", loginUser.getUsername());//当前登录用户
            queryWrapper.orderByAsc("sn");
            Page<ProductionOrderInfo> page = new Page<ProductionOrderInfo>(pageNo, pageSize);
            IPage<ProductionOrderInfo> pageList = productionOrderInfoService.page(page, queryWrapper);
            return Result.OK(pageList);
        }
	}

	 /**
      * 获取子数据
      * @param productionOrderInfo
      * @param req
      * @return
      */
	@AutoLog(value = "生产工单-获取子数据")
	@ApiOperation(value="生产工单-获取子数据", notes="生产工单-获取子数据")
	@GetMapping(value = "/childList")
	public Result<?> queryPageList(ProductionOrderInfo productionOrderInfo,HttpServletRequest req) {
		QueryWrapper<ProductionOrderInfo> queryWrapper = QueryGenerator.initQueryWrapper(productionOrderInfo, req.getParameterMap());
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		queryWrapper.eq("is_merged", 0);//被合并的工单不再显示
        queryWrapper.eq("is_splited", 0);//被拆过的工单不再显示
        queryWrapper.eq("store_by", loginUser.getUsername());//当前登录用户
		List<ProductionOrderInfo> list = productionOrderInfoService.list(queryWrapper);
		IPage<ProductionOrderInfo> pageList = new Page<>(1, 10, list.size());
        pageList.setRecords(list);
		return Result.OK(pageList);
	}

    /**
      * 批量查询子节点
      * @param parentIds 父ID（多个采用半角逗号分割）
      * @return 返回 IPage
      * @param parentIds
      * @return
      */
	@AutoLog(value = "生产工单-批量获取子数据")
    @ApiOperation(value="生产工单-批量获取子数据", notes="生产工单-批量获取子数据")
    @GetMapping("/getChildListBatch")
    public Result<?> getChildListBatch(@RequestParam("parentIds") String parentIds) {
        try {
        	LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            QueryWrapper<ProductionOrderInfo> queryWrapper = new QueryWrapper<>();
            List<String> parentIdList = Arrays.asList(parentIds.split(","));
            queryWrapper.in("pid", parentIdList);
            queryWrapper.eq("is_merged", 0);//被合并的工单不再显示
            queryWrapper.eq("is_splited", 0);//被拆过的工单不再显示
            queryWrapper.eq("store_by", loginUser.getUsername());//当前登录用户
            List<ProductionOrderInfo> list = productionOrderInfoService.list(queryWrapper);
            IPage<ProductionOrderInfo> pageList = new Page<>(1, 10, list.size());
            pageList.setRecords(list);
            return Result.OK(pageList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.error("批量查询子节点失败：" + e.getMessage());
        }
    }
	
	/**
	 *   添加
	 *
	 * @param productionOrderInfo
	 * @return
	 */
	@AutoLog(value = "生产工单-添加")
	@ApiOperation(value="生产工单-添加", notes="生产工单-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody ProductionOrderInfo productionOrderInfo) {
		productionOrderInfoService.addProductionOrderInfo(productionOrderInfo);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param productionOrderInfo
	 * @return
	 */
	@AutoLog(value = "生产工单-编辑")
	@ApiOperation(value="生产工单-编辑", notes="生产工单-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody ProductionOrderInfo productionOrderInfo) {
		productionOrderInfoService.updateProductionOrderInfo(productionOrderInfo);
		return Result.OK("编辑成功!");
	}
	
	
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "生产工单-通过id删除")
	@ApiOperation(value="生产工单-通过id删除", notes="生产工单-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		productionOrderInfoService.deleteProductionOrderInfo(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "生产工单-批量删除")
	@ApiOperation(value="生产工单-批量删除", notes="生产工单-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.productionOrderInfoService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功！");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "生产工单-通过id查询")
	@ApiOperation(value="生产工单-通过id查询", notes="生产工单-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		ProductionOrderInfo productionOrderInfo = productionOrderInfoService.getById(id);
		if(productionOrderInfo==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(productionOrderInfo);
	}
	
	
	/**
	 * 通过订单id查询拟生成的开单单列表
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "生产工单-通过订单id查询拟生成的开单单列表")
	@ApiOperation(value="生产工单-通过订单id查询拟生成的开单单列表", notes="生产工单-通过订单id查询拟生成的开单单列表")
	@GetMapping(value = "/queryOpenListByOrderId")
	public Result<?> queryOpenListByOrderId(@RequestParam(name="orderId",required=true) String orderId, @RequestParam(name="styleId",required=false) String styleId) {
		List<OpenProdOrderVO> openList = productionOrderInfoService.queryOpenListByOrderId(orderId,styleId);
		if(openList == null || openList.size() == 0) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(openList);
	}
	
	/**
	 * 通过订单id和款式id查询物料列表
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "生产工单-通过订单id和款式id查询物料列表")
	@ApiOperation(value="生产工单-通过订单id和款式id查询物料列表", notes="生产工单-通过订单id和款式id查询物料列表")
	@GetMapping(value = "/queryBomListByOrderId")
	public Result<?> queryBomListByOrderId(@RequestParam(name="orderId",required=true) String orderId,@RequestParam(name="styleId",required=false) String styleId) {
		List<OpenBomVO> openList = productionOrderInfoService.queryBomListByOrderId(orderId,styleId);
		if(openList == null || openList.size() == 0) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(openList);
	}
	

	
	/**
	 * 开单操作
	 * @param OpenProdOrderVO
	 * @return
	 */
	@AutoLog(value = "生产工单-开单")
	@ApiOperation(value="生产工单-开单", notes="生产工单-开单")
	@PostMapping(value = "/openProdOrder")
	@Transactional
	public Result<?> openProdOrder(@RequestBody OpenProdOrderFormVO formVO) {
		String orderInfoId = formVO.getId();//订单ID
		String styleId = formVO.getStyleId();//款式ID
		List<OpenProdOrderVO> list = formVO.getOpenList();
		boolean isSuc = false;
		if(list != null && list.size() > 0) {
			LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
			for(OpenProdOrderVO vo : list) {
				String receiveBy = vo.getReceiveBy();//接收人
				String sn = vo.getSn();//拆分序号
				String prodOrderCode = String.valueOf(FillRuleUtil.executeRule("prod_num_code",null));//工单号
				ProductionOrderInfo productionOrderInfo = new ProductionOrderInfo();
				productionOrderInfo.setSendBy(loginUser.getUsername());
				productionOrderInfo.setSendDept(sysDepartService.queryUserDeparts(loginUser.getId()).get(0).getId());
				productionOrderInfo.setSendTime(new Date());
				productionOrderInfo.setReceiveBy(receiveBy);//接收人
				productionOrderInfo.setReceiveDept(sysDepartService.queryDepartsByUsername(receiveBy).get(0).getId());//接收部门
				productionOrderInfo.setSn(sn);//拆分页
				productionOrderInfo.setProdOrderCode(prodOrderCode);//工单号
				productionOrderInfo.setOrderInfoId(orderInfoId);//订单ID
				productionOrderInfo.setStyleCusInfoId(vo.getCusStyleId());//款式ID
				productionOrderInfo.setProdOrderType(1);//工单类型：1开单单 2拆单单 3回收单 4补单单 5合并单
				productionOrderInfo.setType(1);//交收类型：1移交、2发出、3收回、4收转、5收货
				productionOrderInfo.setCount(vo.getCount());//数量
				productionOrderInfo.setWithStoneWeight(null);//重量(连石重)
				productionOrderInfo.setPureStoneWeight(null);//石重
				productionOrderInfo.setWeight(vo.getGoldWeight());//净重(净金重)
				productionOrderInfo.setNoAttritionWeight(null);//不计耗重
				productionOrderInfo.setOtherAccessoryWeight(null);//其他配件重
				productionOrderInfo.setAccessoryCount(null);//配件数
				productionOrderInfo.setAttritionRate(vo.getAttritionRate());//耗率
				productionOrderInfo.setGiveAttrition(null);//给耗
				productionOrderInfo.setGate(null);//水口或链尾
				productionOrderInfo.setStatus(1);//0待分配 1待接收 2做货中 3做货完成
				productionOrderInfo.setPid("0");//根节点
				isSuc = productionOrderInfoService.save(productionOrderInfo);
				isSuc = cusStyleInfoService.openWorkOrder(vo.getCusStyleId());
				try {//发送站内消息提醒
					SysUser receiveUser = userMapper.getUserByName(receiveBy);
					SysAnnouncementController announcementController = (SysAnnouncementController) SpringContextUtils.getBean(SysAnnouncementController.class);
					String title = "生产开单通知"+"(工单号："+prodOrderCode +")";
					String msgContent = "工单号："+prodOrderCode +"，数量："+productionOrderInfo.getCount()+"，请安排生产计划。详情登录查看生产跟单系统。";
					announcementController.addAndSend(title, msgContent, 1, receiveUser.getId()+",");
				} catch (ParseException e) {
					e.printStackTrace();
					isSuc = false;
				}
			}
			if(isSuc) {
				CusOrderInfo cusOrderInfo = cusOrderInfoService.getById(orderInfoId);
				if(cusOrderInfo.getStatus() == 3) {//订单仍是待开工单状态。0暂存草稿 1待审单 -1审单不通过 2待转生产单 3待开工单 4已开工单 5完成工单
					int allOrderStyleCount = cusOrderInfoMapper.countAllOrderStyle(orderInfoId);
					int openedStyleCount = cusOrderInfoMapper.countOpenedOrderStyle(orderInfoId);
					if(openedStyleCount == allOrderStyleCount) {//如果该订单下的款式都已开工单，则更新订单状态为：4已开工单
						cusOrderInfoService.updateStatus(orderInfoId, 4);
					}
				}
				
			}
		}
		return isSuc ? Result.ok("开工单成功！") : Result.error("开工单失败！");
	}
	
	
	/**
	 * 通过订单id获取下一拆分页的字符串
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "通过订单id获取下一拆分页的字符串")
	@ApiOperation(value="通过订单id获取下一拆分页的字符串", notes="通过订单id获取下一拆分页的字符串")
	@GetMapping(value = "/getNextStartSn")
	public Result<?> getNextStartSn(@RequestParam(name="orderInfoId",required=true) String orderInfoId) {
		String startSn = productionOrderInfoService.getNextStartSn(orderInfoId);
		return Result.OK(startSn);
	}
	
	/**
	 *  拆子工单
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "生产工单-拆子工单")
	@ApiOperation(value="生产工单-拆子工单", notes="生产工单-拆子工单")
	@PostMapping(value = "/splitChild")
	@Transactional
	public Result<?> splitChild(@RequestBody JSONObject params) {
		Integer count = params.getInteger("count");//存货数量
		Integer takeCount = params.getInteger("takeCount");//拆分数量
		Integer every = params.getInteger("every");//每页数量
		String pid = params.getString("pid");//父工单主键ID
		String styleCusInfoId = params.getString("styleCusInfoId");//款式ID
		String orderInfoId = params.getString("orderInfoId");//订单ID
		if(takeCount <= 0) {
			Result.error("拆分数量不能为0！");
		}
		if(takeCount > count) {
			Result.error("拆分数量不能超过存货数量("+count+")！");
		}
		Integer snCount = Math.floorDiv(takeCount, every);
		Integer sub = takeCount - snCount*every;
		System.out.println(sub);
		boolean isSuc = false;
		String maxSnString = productionOrderInfoMapper.getMaxSnByOrderInfoId(orderInfoId);
		Integer start = Integer.parseInt(maxSnString)+1;
		Integer end = Integer.parseInt(maxSnString)+snCount;
		int k = 0 ;
		String str = "";
		for(int i=start;i<=end;i++) {
			k++;
			int everyCount = every;
			if( i == end && sub > 0) {//拆分结果计算出来的数量小于总数量
				everyCount += sub;
			}
			String sn = this.getSn(i);//拆分序号
			if(i == start) {
				str +=","+sn+",...";
			} else if(i == end) {
				str +=","+sn;
			}
			
			String prodOrderCode = String.valueOf(FillRuleUtil.executeRule("prod_num_code",null));//工单号
			ProductionOrderInfo productionOrderInfo = new ProductionOrderInfo();
			productionOrderInfo.setReceiveBy(null);//接收人
			productionOrderInfo.setReceiveDept(null);//接收部门
			productionOrderInfo.setSn(sn);//拆分页
			productionOrderInfo.setProdOrderCode(prodOrderCode);//工单号
			productionOrderInfo.setOrderInfoId(orderInfoId);//订单ID
			productionOrderInfo.setStyleCusInfoId(styleCusInfoId);//款式ID
			productionOrderInfo.setProdOrderType(2);//工单类型：1开单单 2拆单单 3回收单 4补单单 5合并单
			//productionOrderInfo.setType(2);//交收类型：1移交、2发出、3收回、4收转、5收货
			productionOrderInfo.setCount(everyCount);//数量
			productionOrderInfo.setWithStoneWeight(null);//重量(连石重)
			productionOrderInfo.setPureStoneWeight(null);//石重
			productionOrderInfo.setWeight(null);//净重(净金重)
			productionOrderInfo.setNoAttritionWeight(null);//不计耗重
			productionOrderInfo.setOtherAccessoryWeight(null);//其他配件重
			productionOrderInfo.setAccessoryCount(null);//配件数
			productionOrderInfo.setAttritionRate(null);//耗率
			productionOrderInfo.setGiveAttrition(null);//给耗
			productionOrderInfo.setGate(null);//水口或链尾
			//productionOrderInfo.setStatus(1);//0待分配 1待接收 2做货中 3做货完成
			productionOrderInfo.setPid(pid);//根节点
			isSuc = productionOrderInfoService.save(productionOrderInfo);
		}
		if(isSuc) {
			UpdateWrapper<ProductionOrderInfo> updateWrapper = new UpdateWrapper<>();
			updateWrapper.eq("id", pid);
			updateWrapper.set("has_child", "1");
			updateWrapper.set("is_splited", "1");
			updateWrapper.set("count", count-takeCount);
			isSuc = productionOrderInfoService.update(updateWrapper);
		}
		if(!"".equals(str)) {
			str = str.substring(1);
		}
		return  isSuc ? Result.ok("成功拆分"+k+"张工单（"+str+"）！") : Result.error("拆工单失败！");
	}
	
	/**
	 *  合并工单
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "生产工单-合并工单")
	@ApiOperation(value="生产工单-合并工单", notes="生产工单-合并工单")
	@DeleteMapping(value = "/merge")
	public Result<?> merge(@RequestParam(name="ids",required=true) String ids) {
		Integer i = this.productionOrderInfoService.mergeByIds(Arrays.asList(ids.split(",")));
		if(i == 0) {
			return Result.ok("合并工单数为0！");
		}
		return Result.ok("（"+i+"）条工单合并成功！");
	}
	
	/**
	 *  交收
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "生产工单-交收")
	@ApiOperation(value="生产工单-交收", notes="生产工单-交收")
	@PostMapping(value = "/settlement")
	public Result<?> settlement(@RequestBody JSONObject jsonObject) {
		ProductionOrderInfo productionOrderInfo = new ProductionOrderInfo();
		LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		String workNo = jsonObject.getString("rcvUserId");
		String receiveBy = userMapper.getUsernameByWorkNo(workNo);
		if(receiveBy != null) {
			productionOrderInfo.setSendBy(loginUser.getUsername());
			productionOrderInfo.setSendTime(new Date());
			productionOrderInfo.setSendDept(sysDepartService.queryUserDeparts(loginUser.getId()).get(0).getId());
			productionOrderInfo.setReceiveBy(receiveBy);
			productionOrderInfo.setReceiveTime(new Date());
			productionOrderInfo.setReceiveDept(sysDepartService.queryDepartsByUsername(receiveBy).get(0).getId());//接收部门
			productionOrderInfo.setStatus(2);
			productionOrderInfo.setCount(jsonObject.getInteger("count"));//数量
			productionOrderInfo.setType(jsonObject.getInteger("type"));//交收类型：1移交、2发出、3收回、4收转、5收货
			productionOrderInfo.setWithStoneWeight(jsonObject.getBigDecimal("withStoneWeight"));//重量(连石重)
			productionOrderInfo.setPureStoneWeight(jsonObject.getBigDecimal("pureStoneWeight"));//石重
			productionOrderInfo.setWeight(jsonObject.getBigDecimal("weight"));//净重(净金重)
			productionOrderInfo.setNoAttritionWeight(jsonObject.getBigDecimal("noAttritionWeight"));//不计耗重
			productionOrderInfo.setOtherAccessoryWeight(jsonObject.getBigDecimal("otherAccessoryWeight"));//其他配件重
			productionOrderInfo.setAccessoryCount(jsonObject.getInteger("accessoryCount"));//配件数
			productionOrderInfo.setAttritionRate(jsonObject.getBigDecimal("attritionRate"));//耗率
			productionOrderInfo.setGiveAttrition(jsonObject.getString("giveAttrition"));//给耗
			productionOrderInfo.setGate(jsonObject.getString("gate"));//水口或链尾
			productionOrderInfo.setOriginalWeight(jsonObject.getBigDecimal("originalWeight"));//原重量
			productionOrderInfo.setDifference(jsonObject.getBigDecimal("difference"));
			productionOrderInfo.setRemark(jsonObject.getString("remark"));//备注
			productionOrderInfo.setId(jsonObject.getString("id"));
			productionOrderInfoService.updateById(productionOrderInfo);
		}
		return Result.OK("交收成功！");
	}
	
	/**
	 * 获取拆分序号
	 * @param sn
	 * @return
	 */
	private String getSn(Integer sn) {
		if(sn < 10) {
			return "0"+String.valueOf(sn);
		} else {
			return String.valueOf(sn);
		}
	}

    /**
    * 导出excel
    *
    * @param request
    * @param productionOrderInfo
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ProductionOrderInfo productionOrderInfo) {
		return super.exportXls(request, productionOrderInfo, ProductionOrderInfo.class, "生产工单");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
		return super.importExcel(request, response, ProductionOrderInfo.class);
    }

}
